/*    
 * Copyright (c) 2013 ISoftStone, Inc.
 * All right reserved.
 *
 * 文件名：      BillingCycleUserServiceImpl.java
 * 作者:     Jacky Wang
 * 创建日期： 2013-7-1 下午03:24:33
 * 版本：           
 *
 */
package com.isoftstone.industry.aaa.core.service.assist.impl;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.isoftstone.industry.persistance.bean.BillingCycle;
import com.isoftstone.industry.persistance.bean.BillingCycleUser;
import com.isoftstone.industry.persistance.bean.User;
import com.isoftstone.industry.aaa.core.dao.assist.BillingCycleUserDao;
import com.isoftstone.industry.aaa.core.service.assist.IBillingCycleUserService;
import com.isoftstone.modules.core.persistence.IGenericDao;
import com.isoftstone.modules.core.service.impl.GenericServiceImpl;

/**
 * @author jacky
 */
@Service
public class BillingCycleUserServiceImpl extends GenericServiceImpl<BillingCycleUser, String> implements IBillingCycleUserService
{
	@Resource
	private BillingCycleUserDao	billingCycleUserDao;

	@Override
	public IGenericDao<BillingCycleUser, String> getDao()
	{
		return billingCycleUserDao;
	}

	@Override
	public void bindUserWithBillingCycle(String userId, String billingCycleId)
	{
		BillingCycleUser entity = billingCycleUserDao.findByBillingCycleAndUser(billingCycleId, userId);
		if (entity == null)
		{
			entity = new BillingCycleUser();
			User user = new User();
			user.setId(userId);
			entity.setUser(user);

			BillingCycle billingCycle = new BillingCycle();
			billingCycle.setId(billingCycleId);
			entity.setBillingCycle(billingCycle);
			billingCycleUserDao.save(entity);
		}

	}
}
